<?php


namespace app\admin\controller;

class Report extends Base
{
    public function report_start()
    {
        if(request()->isAjax()) {
            $data = input('post.');
            if(!is_array($data)) { return show('500','非法传参',[]); }  //检测数据
            if(!isset($data['report_is_open'])) { $data['report_is_open'] = "off"; }    //检测站点开关
            $lists = [
                [
                    'id'   => '12',
                    'name' => 'report_start',
                    'type' => '5',
                    'value'  => strtotime($data['report_start'])
                ],
                [
                    'id'   => '13',
                    'name' => 'report_is_open',
                    'type' => '5',
                    'value'  => $data['report_is_open']
                ]
            ];
            try{
                $res = Model('Config')->saveAll($lists);
            }catch (\Exception $e) {
                return show('200',$e->getMessage(),'[]');
            }
            return show('200','修改成功','1');
        }else {
            $start_time = Model('Config')->get_this_config_value('5','report_start');
            $is_open = Model('Config')->get_this_config_value('5','report_is_open');
            $this->assign([
                'start_time' => date( "Y-m-d",$start_time['value']),
                'is_open' => $is_open['value'],
            ]);
            return $this->fetch();
        }
    }
}